package com.example.userservice.controller;

import com.example.userservice.pojo.User;
import com.example.userservice.service.UserService;
import com.example.userservice.utils.ResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private RabbitTemplate rebbitTemplate;
    Logger logger = LoggerFactory.getLogger(getClass());

    @GetMapping("/{id}")
    public ResultData queryById(@PathVariable Long id) throws InterruptedException {
        ResultData resultData = new ResultData();

        //Thread.sleep(1000);
        logger.debug("服务被调用"+System.currentTimeMillis());
        logger.info("info1");
        logger.error("error1");
        logger.warn("warn1");
        logger.trace("trace1");
        System.out.println("控制台打印中服务被调用"+System.currentTimeMillis());
        System.out.println("控制台打印中服务被调用"+System.currentTimeMillis());
        User user = userService.queryById(id);

        resultData.setMsg("查询成功");
        resultData.setCode(200);
        resultData.setFlag(true);
        resultData.setData(user);
        return resultData;
    }

    @PostMapping("/queryUser")
    public ResultData queryUser(@RequestBody  User user){
        List<User> userList = userService.queryUserList();

        for(User userPoJo:userList){
            System.out.println(userPoJo);
        }
        return null;
    }
    @GetMapping("/mq/{id}")
    public ResultData mq(@PathVariable Long id){

        return null;
    }

}
